package com.sskj.givecoin.v.activity;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.scwang.smartrefresh.layout.util.DensityUtil;

import com.sskj.givecoin.R;
import com.sskj.givecoin.common.Constants;
import com.sskj.givecoin.common.adapter.BaseAdapter;
import com.sskj.givecoin.common.adapter.MyFragmentPagerAdapter;
import com.sskj.givecoin.common.widget.HeyTabLayout;
import com.sskj.givecoin.m.bean.RechargeListBean;
import com.sskj.givecoin.p.activity.CapitalDetailPresenter;
import com.sskj.givecoin.v.base.BaseActivity;
import com.sskj.givecoin.v.fragment.CapitalDetailsFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;


/**
 * ProjectName：bfex
 * DESC: (账单明细)
 * Created by 李岩 on 2018/6/29 0029
 * updateName:(修改人名称)
 * updateTime:(修改时间)
 * updateDesc:(修改内容)
 */
public class CapitalDetailsActivity extends BaseActivity<CapitalDetailPresenter> {


    @BindView(R.id.information_back)
    ImageView mInformationBack;
    @BindView(R.id.asset_manage_tablayout)
    HeyTabLayout mAssetManageTablayout;
    @BindView(R.id.capital_details_viewpager)
    ViewPager mCapitalDetailsViewPager;
    private BaseAdapter<RechargeListBean> mAdapter;
    private CharSequence mCurrentTabText;
    List<Fragment> fragments = new ArrayList<>();
    List<String> titles = new ArrayList<>();

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_capital_details;
    }

    @Override
    public CapitalDetailPresenter getPresenter() {
        return new CapitalDetailPresenter();
    }

    @Override
    protected void initView() {
        super.initView();
        int assetId = getIntent().getIntExtra(Constants.INTENT_ASSET_ID, -1);
        mInformationBack.setOnClickListener(v -> finish());

        LinearLayout linearLayout = (LinearLayout) mAssetManageTablayout.getChildAt(0);
        linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        linearLayout.setDividerDrawable(getResources().getDrawable(R.drawable.shape_rectangle_gray));
        linearLayout.setDividerPadding(DensityUtil.dp2px(20));


        titles.add(getResources().getString(R.string.recharge_currency)); // 充币
        titles.add(getResources().getString(R.string.extract_coins));  // 提币
        titles.add(getResources().getString(R.string.asset_bill));
        for (int i = 0; i < 3; ++i) {
            CapitalDetailsFragment fragment = new CapitalDetailsFragment();
            Bundle bundle = new Bundle();
            bundle.putInt("index", i);
            bundle.putInt("assetId", assetId);
            fragment.setArguments(bundle);
            fragments.add(fragment);
        }
        mCapitalDetailsViewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(), titles, fragments));

        mAssetManageTablayout.setupWithViewPager(mCapitalDetailsViewPager);
        mCapitalDetailsViewPager.setCurrentItem(0);
        mCapitalDetailsViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                ((CapitalDetailsFragment) fragments.get(position)).update();
            }
        });
    }
}
